<template>
    <mescroll-uni
        ref="mescrollRef"
        @init="mescrollInit"
        :height="height"
        :down="downOption"
        @down="downRefresh"
        :up="upOption"
        @up="getData">
        <view class="list">
            <detail-list-item
                v-for="(item, index) in datas"
                :item="item"
                :index="index"
                :key="index"></detail-list-item>
        </view>
    </mescroll-uni>
</template>

<script>
import DetailListItem from "./detail-list-item.vue"
import { getArApDetailList, getPayDetailList } from "@/service/api/erp.js"
export default {
    components: {
        DetailListItem,
    },
    props: {
        height: {
            type: String,
            default: "300px",
        },
        type: {
            type: String / Number,
            default: 1,
        },
    },
    data() {
        return {
            datas: [],
            allLength: 0,
            data: [],
            productList: [],
            param: {
                startDate: "",
                endDate: "",
            },
            downOption: {
                use: true,
            },
            isLoaded: false,
        }
    },
    mounted() {
        // this.refresh()
    },
    methods: {
        //获取列表数据
        getData(page) {
            let param = this.param
            param.pageNumber = page.num
            param.pageSize = page.size
            let getDatas
            if (this.type == 1) {
                getDatas = getArApDetailList
            } else {
                getDatas = getPayDetailList
            }
            getDatas(param).then((res) => {
                if (res.State == 1) {
                    this.mescroll.endBySize(res.Data.length, res.RecordAmout)
                    this.datas = this.datas.concat(res.Data)
                    this.allLength = res.RecordAmout
                    this.isLoaded = true
                    this.$emit("totalBack", res.RecordAmout)
                } else {
                    this.mescroll.endBySize(0, 0)
                }
            })
        },
        //刷新
        refresh(param) {
            if (param) {
                this.param = param
            }
            this.downRefresh()
        },
        //刷新
        downRefresh() {
            this.datas = []
            this.mescroll.resetUpScroll()
        },
    },
}
</script>

<style lang="scss">
.list {
    // padding: 0 $app-page-padding;
    margin: 0 $app-page-padding 0;
}
</style>
